Ext.define('PJ.view.trainingmanagement.OperatingCourseEdit', {
    extend: 'AM.default.DefaultWindowForm',
    requires: ['AM.default.DefaultDateField', 
               'AM.default.DateTime', 
               'AM.default.jsonp.DefaultSubmitJsonp'],
    
    modal: true,// 开启不允许点击其他组件
    frame: true,
    notEdit: true,
    width: 605,
    height: 180,
    isSame: false,
    isEdit: null,

    initComponent: function(){
    	var me = this;
    	var bt = '<span style="color:red;">*</span>';
    	me.items= [{
    		xtype: "container",
    		layout: 'column',
    		width: 580,
            collapsible: false, //显示三角
            defaults: {
    			xtype: 'textfield',
            	labelAlign: 'right',
            	labelWidth: 65,
            	allowBlank: true, // 显示红框是否必填,默认显示,
            	padding: '0 0 5 0',
            	columnWidth: .5
            },
    		items: [{
    			fieldLabel: bt + '课程名',
    			name: 'courseName',
    			allowBlank: false,
                listeners: {
                	change: function(textField){
                		if(textField.getValue() && textField.getValue().length > 30){
                			Orchid.alert('提示','该输入项最多输入30个字符！');
                		}
                	}
                },
                maxLength: 30
    		}, {
				xtype: 'defaultDate',
				fieldLabel: '日期',
				name: 'speakDateStr',
				editable: false
			}, {
                xtype: 'combo',
                fieldLabel: bt + '课程类型',
                name: 'speakway',
                blankText: "请选择",
                allowBlank: false,
                editable: false,
                queryMode: 'local',//'remote',
                store: Ext.create("Ext.data.ArrayStore", {
                    singleton: true,
                    fields: [{
                        name: 'value',
                        mapping: "dataCode",
                        type: 'string'
                    }, {
                        name: 'text',
                        mapping: "dataName",
                        type: 'string'
                    }],
                    proxy: {
                        type: gj_onlineLearning_constant.loadType,
                        url: me.grid.store.courseTypeUrl + '?typeCode=skfs',
                        reader: Ext.create('Ext.data.reader.Json', {
                            type: 'json',
                            root: 'data',
                            successProperty: 'success'
                        })
                    },
                    autoLoad: true
                }),
                valueField: "value",
                displayField: "text",
                maxLength: 20
            }, {
                xtype: "combo",
                fieldLabel: "授课时间",
                name: 'speakTime',
                blankText: "请选择",
                editable: false,
                queryMode: 'local',//'remote',
                store: Ext.create("Ext.data.ArrayStore", {
                    singleton: true,
                    fields: [{
                        name: 'value',
                        mapping: "dataCode",
                        type: 'string'
                    }, {
                        name: 'text',
                        mapping: "dataName",
                        type: 'string'
                    }],
                    proxy: {
                        type: gj_onlineLearning_constant.loadType,
                        url: me.grid.store.courseTimeTypeUrl + '?typeCode=speakTime',
                        reader: Ext.create('Ext.data.reader.Json', {
                            type: 'json',
                            root: 'data',
                            successProperty: 'success'
                        })
                    },
                    autoLoad: true
                }),
                valueField: 'value',
                displayField: 'text',
                editable: false
            }, {
    			fieldLabel: '授课教师',
    			name: 'speaker',
                listeners: {
                	change: function(textField){
                		if(textField.getValue() && textField.getValue().length > 20){
                			Orchid.alert('提示','该输入项最多输入20个字符！');
                		}
                	}
                },
                maxLength: 50
    		}, {
    			fieldLabel: '教师单位',
    			name: 'speakdept',
                listeners: {
                	change: function(textField){
                		if(textField.getValue() && textField.getValue().length > 50){
                			Orchid.alert('提示','该输入项最多输入50个字符！');
                		}
                	}
                },
                maxLength: 50
    		}, {
    			fieldLabel: '教师职务',
    			name: 'speakDuty',
                listeners: {
                	change: function(textField){
                		if(textField.getValue() && textField.getValue().length > 30){
                			Orchid.alert('提示','该输入项最多输入30个字符！');
                		}
                	}
                },
                maxLength: 50
    		}, {
                xtype: 'hidden',
                name: 'classCourseId'
            }]
    	}];
        this.buttons = [{
            text: '确定',
            scope: this,
            handler: function(button, event){
                var win = button.up('window');
                win.sub();
            }
        }, {
            text: '取消',
            scope: this,
            handler: this.close
        }];
        this.callParent(arguments);
    },
    sub: function(){
    	var win = this;
    	var form = win.down('form');
    	var baseForm = form.getForm();
    	if (!baseForm.isValid()) {
    		return;
    	}
    	if(gj_onlineLearning_constant.loadType == "jsonp"){
    		form.getForm().doAction('submitJsonp',{
    			submitEmptyText:false,
    			url: win.grid.store.updateUrl,
    			params: {},
    			success: function(f, action){
    				if (action.result.success) {
    					Ext.Msg.alert('消息', "更新成功！", function(){
    						var gridPanel = win.grid;
    						var store = gridPanel.getStore();
    						store.reload();
    						win.grid.up("window").saveToken();
    						win.close();
    					});
    				}
    			},
    			failure: function(f, action){
    				if (action.result) {
    					Orchid.alert('错误', action.result.msg || "操作失败!");
    					win.grid.up("window").saveToken();
    				}
    			}
    		});
    	}else if(gj_onlineLearning_constant.loadType == "ajax"){
    		win.submit({
    			submitEmptyText:false,
    			url: win.grid.store.updateUrl,
    			params: {},
    			success: function(f, action){
    				if (action.result.success) {
    					Ext.Msg.alert('消息', '更新成功！', function(){
    						var gridPanel = win.grid;
    						var store = gridPanel.getStore();
    						store.reload();
    						win.grid.up("window").saveToken();
    						win.close();
    					});
    				}
    			},
    			failure: function(f, action){
    				if (action.result) {
    					Orchid.alert('错误', action.result.msg || "系统出错,请联系管理员!");
    					win.grid.up("window").saveToken();
    				}
    			}
    		});
    	}
    }
});
